package org.rasterfun.language2.num

import org.rasterfun.language2.{NumKind, ThenElse, Expression}
import org.rasterfun.language2.bool.Bool
import java.lang.String

object Num {
  val MinusOne = Num(-1)
  val Zero = Num(0)
  val One = Num(1)
  def apply(v: Float): NumConstant = NumConstant(v)
  def apply(v: Int): NumConstant = NumConstant(v.toFloat)
  def apply(v: Double): NumConstant = NumConstant(v.toFloat)
}

/**
 * A numerical expression.
 * 
 * @author Hans Haggstrom
 */
trait Num extends Expression {

	def kind = NumKind

  def >   (n: Num) = Greater(this, n)
  def <   (n: Num) = Less(this, n)
  def >=  (n: Num) = GreaterOrEqual(this, n)
  def <=  (n: Num) = LessOrEqual(this, n)
  def === (n: Num) = Equal(this, n)
  def !== (n: Num) = NotEqual(this, n)

  def + (n: Num) = Add(this, n)
  def - (n: Num) = Sub(this, n)
  def * (n: Num) = Mul(this, n)
  def / (n: Num) = Div(this, n)



  def unary_- = Neg(this)

  def otherwise(n: Num) = NumThenElse(this, n)


  override def operation(op: String, other: Expression): Expression = op.trim.toLowerCase match {
    case ">" => >(other)
    case "<" => <(other)
    case ">=" => >=(other)
    case "<=" => <=(other)
    case "==" => ===(other)
    case "!=" => !==(other)

    case "+" => + (other)
    case "-" => - (other)
    case "*" => * (other)
    case "/" => / (other)
  }


}

